<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
  <script src="../../vue-router.js"></script>

  <style>
    .active {
      font-weight: 500;
      color: red;
    }
  </style>
</head>

<body>

  <div id="app">

    <ul>

      <router-link tag="li" to="/position" active-class="active">职位</router-link>
      <router-link tag="li" to="/search" active-class="active">搜索</router-link>
    </ul>

    <router-view></router-view>


    <button @click="go">后端开发</button>

  </div>

  <script>
    const position = {
      template: `<div>
        <router-link active-class="active" to="/position/fe">前端开发</router-link>
        <router-link active-class="active" to="/position/be">后端开发</router-link>
        <router-view></router-view>
        </div>`
    }

    const search = {
      template: `<div>search</div>`
    }



    var router = new VueRouter({
      mode: 'hash',
      routes: [
        {
          path: '/',
          redirect: '/position/fe'
        },
        {
          path: '/position',
          component: position,
          redirect: '/position/fe',
          children: [
            {
              path: '/position/fe',
              component: {
                template: '<div>postion fe</div>'
              }
            },
            {
              path: '/position/be',
              name: 'be',
              component: {
                template: '<div>postion be</div>'
              }
            }
          ]
        },
        {
          path: '/search',
          component: search
        },
        {
          path: '*',
          component: {
            template: `<h1>404 page not found !</h1>`
          }
        }
      ]
    })

    var vm = new Vue({
      router,
      el: '#app',
      methods: {
        go() {
          // this.$router.push('/position/be')
          // this.$router.push({
          //   path: '/position/be'
          // })
          //命名式路由
          // this.$router.push({
          //   name: "be"
          // })
          router.push({
            name: "be"
          })

        }
      }
    })

  </script>

</body>

</html>